<script setup lang="ts">
import { useMemberStore } from '@/stores'
import { onLoad } from '@dcloudio/uni-app'
import Api from '@/services'

const memberStore = useMemberStore()
let code = ''

onLoad(async () => {
  const res = await wx.login()
  code = res.code
})

const onGetPhoneNumber = async () => {
  const res = await Api.LoginAPI.getSimpleLogin('13536940617')
  memberStore.setProfile(res.result)
  uni.showToast({
    title: '登录成功',
    icon: 'success',
  })
  setTimeout(() => {
    // uni.switchTab({ url: '/pages/my/my' })
    uni.navigateBack()
  }, 500)
}
</script>

<template>
  <view class="viewport">
    <view class="logo">
      <image
        class="pic"
        src="https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/images/logo_icon.png"
      ></image>
    </view>
    <!-- 登录 -->
    <view class="login">
      <button class="real-phone">
        <text class="icon icon-phone"></text>
        手机号快捷登录
      </button>

      <view class="extra">
        <view class="caption">
          <text>其他登录方式</text>
        </view>
        <view class="options">
          <!-- 通用模拟登录 -->
          <button open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">
            <text class="icon icon-phone"></text>
            模拟快捷登录
          </button>
        </view>
      </view>
    </view>
  </view>
</template>

<style lang="scss">
.viewport {
  height: 100vh;
  .logo {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40vh;
    width: 100%;
    .pic {
      width: 220rpx;
      height: 220rpx;
    }
  }
  .login {
    padding: 0 40rpx;
    .real-phone {
      font-size: 32rpx;
      color: #fff;
      background-color: #27ba9b;
      border-radius: 70rpx;
    }
    .extra {
      box-sizing: border-box;
      padding: 60rpx;
      width: 670rpx;
      height: 300rpx;

      .caption {
        padding-bottom: 60rpx;
        width: 100%;
        line-height: 1;
        font-size: 26rpx;
        height: 30rpx;
        border-top: 1px solid #ddd;
        color: #999;
        position: relative;
        text {
          position: absolute;
          top: -15rpx;
          left: 50%;
          transform: translate(-50%);
          background: #fff;
        }
      }
      .options {
        display: flex;
        justify-content: center;
        align-items: center;

        button {
          color: #444;
          font-size: 30rpx;
          padding: 0;
          background-color: transparent;
          .icon {
            display: block;
            padding: 0;

            &::before {
              width: 80rpx;
              height: 80rpx;
              padding: 10rpx;
              border: 1px solid #444;
              border-radius: 50%;
              font-size: 40rpx;
            }
          }
        }
      }
    }
  }
}
</style>
